package com;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import connection.DBConnection;

/**
 * Servlet implementation class QuickFunctionServlet3
 */
@WebServlet("/QuickFunctionServlet3")
public class QuickFunctionServlet3 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QuickFunctionServlet3() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String value1=request.getParameter("vouchertype");
		DBConnection dbc=new DBConnection();	
		 Connection con=dbc.getNewConnection();
		 
		 Statement st = null;
		 ResultSet rs = null;
		 String r1="",r2="",r3="",r33="";
		 try 
			{
				st = con.createStatement();
				
				
				   
				    try{
				    rs=st.executeQuery("select ccode from customermaster where ccode ='"+value1+"' ");
				    while(rs.next()) 
					{ 
						r1=rs.getString(1);
						System.out.println(r1);
						}}
				    catch(Exception e1)
				    {
				    	
				    }
				    try{
					    rs=st.executeQuery("select scode from suppliermaster where scode ='"+value1+"' ");
					    while(rs.next()) 
						{ 
							r2=rs.getString(1);
							}}
					    catch(Exception e2)
					    {
					    	
					    }
				    try{
					    rs=st.executeQuery("select bname,micr from bankmaster where micr ='"+value1+"' ");
					    while(rs.next()) 
						{ 
					    	r33=rs.getString(1);
							r3=rs.getString(2);
							}}
					    catch(Exception e3)
					    {
					    	
					    }
				    if(value1.equals(r1))
				    {
				    	request.setAttribute("accountcode",value1);
				        RequestDispatcher requestDispatcher; 
				        requestDispatcher = request.getRequestDispatcher("CustomerLedgerReport.jsp" ) ;
				        requestDispatcher.forward(request,response);
				    }
				    else if(value1.equals(r2))
				    {
				    	request.setAttribute("accountcode",value1);
				        RequestDispatcher requestDispatcher; 
				        requestDispatcher = request.getRequestDispatcher("SupplierLedgerReport.jsp" ) ;
				        requestDispatcher.forward(request,response);
				    }
				    else  if(value1.equals(r3))
				    {
				    	request.setAttribute("bankname",r33);
				        RequestDispatcher requestDispatcher; 
				        requestDispatcher = request.getRequestDispatcher("BankLedgerReport.jsp" ) ;
				        requestDispatcher.forward(request,response);
				    }
			}
catch(Exception e)
{
	
}
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
